package com.cloudm.technician.common.splash

import com.cloudm.technician.BaseTestRule
import com.cloudm.technician.data.preferences.PreferencesHelper
import com.cloudm.technician.ui.modules.common.splash.SplashContract
import com.cloudm.technician.ui.modules.common.splash.SplashPresenter
import org.junit.Before
import org.junit.Test
import org.mockito.Mock
import org.mockito.Mockito.*
import org.mockito.MockitoAnnotations

/**
 * 作者: wesley
 * 时间: 2017/12/18
 * 描述: 闪屏页presenter层的单元测试
 */
class SplashPresenterTest : BaseTestRule() {

    @Mock private lateinit var view: SplashContract.View

    @Mock private lateinit var preferencesHelper: PreferencesHelper

    private lateinit var presenter: SplashPresenter

    @Before
    fun setUp() {
        MockitoAnnotations.initMocks(this)
        presenter = SplashPresenter(view, preferencesHelper)
    }


    @Test
    fun testOpenActivityOne() {
        `when`(preferencesHelper.isFirstTimeIn).thenReturn(true)
        `when`(view.isActive).thenReturn(true)
        presenter.openActivity(0)
        verify(view).openGuideActivity()
    }


    @Test
    fun testOpenActivityTwo() {
        `when`(preferencesHelper.isFirstTimeIn).thenReturn(false)
        `when`(preferencesHelper.isLogin).thenReturn(false)
        `when`(view.isActive).thenReturn(true)
        presenter.openActivity(0)
        verify(view, never()).openGuideActivity()
        verify(view).openLoginActivity()
    }


    @Test
    fun testOpenActivityThree() {
        `when`(preferencesHelper.isFirstTimeIn).thenReturn(false)
        `when`(preferencesHelper.isLogin).thenReturn(true)
        `when`(view.isActive).thenReturn(true)
        presenter.openActivity(0)
        verify(view, never()).openGuideActivity()
        verify(view, never()).openLoginActivity()
        verify(view).openHomeActivity()
    }


    @Test
    fun testOpenActivityFour() {
        `when`(preferencesHelper.isFirstTimeIn).thenReturn(false)
        `when`(preferencesHelper.isLogin).thenReturn(true)
        `when`(view.isActive).thenReturn(false)
        presenter.openActivity(0)
        verify(view, never()).openGuideActivity()
        verify(view, never()).openLoginActivity()
        verify(view, never()).openHomeActivity()
    }
}